<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:s="http://jboss.com/products/seam/taglib"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:a="http://richfaces.org/a4j"
    xmlns:rich="http://richfaces.org/rich"
    template="layout/template.xhtml">

<ui:define name="body">

    <h:form id="person" styleClass="edit">

        <rich:panel>
            <f:facet name="header">#{personHome.managed ? 'Edit' : 'Add'} Person</f:facet>


            <s:decorate id="personidField" template="layout/edit.xhtml">
                <ui:define name="label">Personid</ui:define>
                <h:inputText id="personid"
                       required="true"
                          value="#{personHome.instance.personid}"
                           size="29">
                    <a:support event="onblur" reRender="personidField" bypassUpdates="true" ajaxSingle="true"/>
                </h:inputText>
            </s:decorate>


            <s:decorate id="firstnameField" template="layout/edit.xhtml">
                <ui:define name="label">Firstname</ui:define>
                <h:inputTextarea id="firstname"
                               cols="80"
                               rows="3"
                           required="true"
                              value="#{personHome.instance.firstname}"/>
            </s:decorate>


            <s:decorate id="lastnameField" template="layout/edit.xhtml">
                <ui:define name="label">Lastname</ui:define>
                <h:inputTextarea id="lastname"
                               cols="80"
                               rows="3"
                           required="true"
                              value="#{personHome.instance.lastname}"/>
            </s:decorate>


            <s:decorate id="userpasswordField" template="layout/edit.xhtml">
                <ui:define name="label">Userpassword</ui:define>
                <h:inputTextarea id="userpassword"
                               cols="80"
                               rows="3"
                           required="true"
                              value="#{personHome.instance.userpassword}"/>
            </s:decorate>


            <div style="clear:both">
                <span class="required">*</span>
                required fields
            </div>

        </rich:panel>

        <div class="actionButtons">

            <h:commandButton id="save"
                          value="Save"
                         action="#{personHome.persist}"
                       disabled="#{!personHome.wired}"
                       rendered="#{!personHome.managed}"/>

            <h:commandButton id="update"
                          value="Save"
                         action="#{personHome.update}"
                       rendered="#{personHome.managed}"/>

            <h:commandButton id="delete"
                          value="Delete"
                         action="#{personHome.remove}"
                      immediate="true"
                       rendered="#{personHome.managed}"/>

            <s:button id="cancelEdit"
                   value="Cancel"
             propagation="end"
                    view="/Person.xhtml"
                rendered="#{personHome.managed}"/>

            <s:button id="cancelAdd"
                   value="Cancel"
             propagation="end"
                    view="/#{empty personFrom ? 'PersonList' : personFrom}.xhtml"
                rendered="#{!personHome.managed}"/>

        </div>
    </h:form>

<rich:tabPanel switchType="ajax">

    <rich:tab label="Timeentries">
        <h:form styleClass="association" id="timeentriesChildren">

            <h:outputText value="There are no timeentries associated with this person."
                       rendered="#{empty personHome.timeentries}"/>

            <rich:dataTable value="#{personHome.timeentries}"
                           var="_timeentry"
                      rendered="#{not empty personHome.timeentries}"
                    rowClasses="rvgRowOne,rvgRowTwo"
                            id="timeentriesTable">
                <rich:column sortBy="#{_timeentry.timeentryid}">
                    <f:facet name="header">Timeentryid</f:facet>
                    <h:outputText value="#{_timeentry.timeentryid}">
                        <f:convertNumber/>
                    </h:outputText>
                </rich:column>
                <rich:column sortBy="#{_timeentry.startdatetime}">
                    <f:facet name="header">Startdatetime</f:facet>
                    <h:outputText value="#{_timeentry.startdatetime}">
                        <s:convertDateTime type="date" dateStyle="short"/>
                    </h:outputText>
                </rich:column>
                <rich:column sortBy="#{_timeentry.enddatetime}">
                    <f:facet name="header">Enddatetime</f:facet>
                    <h:outputText value="#{_timeentry.enddatetime}">
                        <s:convertDateTime type="date" dateStyle="short"/>
                    </h:outputText>
                </rich:column>
            </rich:dataTable>

        </h:form>

        <f:subview rendered="#{personHome.managed}" id="timeentries">
        <div class="actionButtons">
            <s:button id="addtimeentry"
                   value="Add timeentry"
                    view="/TimeentryEdit.xhtml"
             propagation="none">
                 <f:param name="personPersonid"
                         value="#{personHome.instance.personid}"/>
                 <f:param name="timeentryFrom" value="Person"/>
            </s:button>
        </div>
        </f:subview>
    </rich:tab>
</rich:tabPanel>
</ui:define>

</ui:composition>
